From b9a6b894946beae97578edfcb88aa45cf686174d Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Fri, 17 Sep 2004 21:04:23 +0000 Subject: [PATCH] Fixed internal styles so -i -f -f works as expected --- gpsbabel/defs.h | 1 + gpsbabel/vecs.c | 3 ++- gpsbabel/xcsv.c | 24 ++++++++++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index cf4ad1c36..21fa18ae2 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -263,6 +263,7 @@ void waypt_flush(queue *); void waypt_flush_all(void); unsigned int waypt_count(void); void free_gpx_extras (xml_tag * tag); +void xcsv_setup_internal_style(const char *style_buf); void xcsv_read_internal_style(const char *style_buf); waypoint * find_waypt_by_name(const char *name); diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index 3bfac7257..a94e12f8a 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -378,6 +378,7 @@ find_vec(char *const vecname, char **opts) } } + xcsv_setup_internal_style( NULL ); xfree(v); return vec->vec; @@ -407,7 +408,7 @@ find_vec(char *const vecname, char **opts) } else { *opts = NULL; } - xcsv_read_internal_style(svec->style_buf); + xcsv_setup_internal_style(svec->style_buf); xfree(v); diff --git a/gpsbabel/xcsv.c b/gpsbabel/xcsv.c index fe22c83dc..da695a1e8 100644 --- a/gpsbabel/xcsv.c +++ b/gpsbabel/xcsv.c @@ -38,6 +38,8 @@ static char *snuniqueopt = NULL; char *prefer_shortnames = NULL; char *xcsv_urlbase = NULL; +static const char *intstylebuf = NULL; + static arglist_t xcsv_args[] = { {"style", &styleopt, "Full path to XCSV style file", NULL, @@ -83,6 +85,7 @@ xcsv_destroy_style(void) queue *elem, *tmp; field_map_t *fmp; ogue_t *ogp; + int internal = 0; /* * If this xcsv_file struct came from a file we can free it all. @@ -158,7 +161,9 @@ xcsv_destroy_style(void) xfree(xcsv_file.mkshort_handle); /* return everything to zeros */ + internal = xcsv_file.is_internal; memset(&xcsv_file, '\0', sizeof(xcsv_file)); + xcsv_file.is_internal = internal; } static const char * @@ -462,6 +467,15 @@ xcsv_read_internal_style(const char *style_buf) } } +void +xcsv_setup_internal_style(const char *style_buf) +{ + xcsv_file_init(); + xcsv_file.is_internal = !!style_buf; + intstylebuf = style_buf; +} + + static void xcsv_rd_init(const char *fname) { @@ -470,7 +484,10 @@ xcsv_rd_init(const char *fname) * if we don't have an internal style defined, we need to * read it from a user-supplied style file, or die trying. */ - if (xcsv_file.is_internal == 0) { + if (xcsv_file.is_internal ) { + xcsv_read_internal_style( intstylebuf ); + } + else { if (!styleopt) fatal(MYNAME ": XCSV input style not declared. Use ... -i xcsv,style=path/to/file.style\n"); @@ -495,7 +512,10 @@ xcsv_wr_init(const char *fname) /* if we don't have an internal style defined, we need to * read it from a user-supplied style file, or die trying. */ - if (xcsv_file.is_internal == 0) { + if (xcsv_file.is_internal ) { + xcsv_read_internal_style( intstylebuf ); + } + else { if (!styleopt) fatal(MYNAME ": XCSV output style not declared. Use ... -o xcsv,style=path/to/file.style\n"); -- 2.30.2